package com.stevenmoon.csdnplus.logic;

import com.google.gson.reflect.TypeToken;
import com.stevenmoon.csdnplus.app.Constants;
import com.stevenmoon.csdnplus.app.Constants.CSDNURL;
import com.stevenmoon.csdnplus.bean.FollowOperationInfo;
import com.stevenmoon.csdnplus.bean.FollowOperationReqBean;
import com.stevenmoon.csdnplus.bean.ResponseResultBean;
import com.stevenmoon.csdnplus.bean.UnReadCountInfo;
import com.stevenmoon.csdnplus.net.RequestParams;
import com.stevenmoon.csdnplus.net.RxNet;
import com.stevenmoon.csdnplus.util.CollectionUtil;
import com.stevenmoon.csdnplus.util.GsonUtil;

import java.util.List;

import rx.Observable;

/**
 * Created by WangJun on 2016/5/7.
 */
public class CommonManager {

    public static Observable<List<String>> getNickNames(List<String> usernames){
        RequestParams rp = new RequestParams(CSDNURL.USER_NICKNAMES);
        rp.put("usernames", CollectionUtil.convertParamList2String(usernames));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<String>>>(){});
    }

    public static Observable<List<String>> getNickName(String username){
        RequestParams rp = new RequestParams(CSDNURL.USER_NICKNAMES);
        rp.put("usernames", username);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<String>>>(){});
    }

    public static Observable<UnReadCountInfo> getUnReadCount(){
        RequestParams rp = new RequestParams(CSDNURL.UNREAD_COUNT);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<UnReadCountInfo>>(){});
    }

    public static Observable<FollowOperationInfo> doFollow(FollowOperationReqBean reqBean){
        RequestParams rp = new RequestParams(Constants.CSDNURL.USER_DO_FOLLOW, GsonUtil.convertBean2Map(reqBean));
        return RxNet.postAndFetchEntity(rp,new TypeToken<ResponseResultBean<FollowOperationInfo>>(){});
    }

    public static Observable<FollowOperationInfo> unFollow(FollowOperationReqBean reqBean){
        RequestParams rp = new RequestParams(Constants.CSDNURL.USER_UN_FOLLOW, GsonUtil.convertBean2Map(reqBean));
        return RxNet.postAndFetchEntity(rp,new TypeToken<ResponseResultBean<FollowOperationInfo>>(){});
    }



}
